package com.linkwechat.system.service.impl;


import com.linkwechat.system.domain.SysTenantVo;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import com.linkwechat.system.mapper.SysTenantMapper;
import com.linkwechat.system.domain.SysTenant;
import com.linkwechat.system.service.ISysTenantService;

import java.util.List;


/**
 * 租户信息Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-05
 */
@Service
public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant> implements ISysTenantService {

    @Override
    public List<SysTenant> queryList(SysTenant sysTenant) {
        LambdaQueryWrapper<SysTenant> lqw = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(sysTenant.getParentCode())){
            lqw.eq(SysTenant::getParentCode ,sysTenant.getParentCode());
        }
        if (StringUtils.isNotBlank(sysTenant.getTenantName())){
            lqw.like(SysTenant::getTenantName ,sysTenant.getTenantName());
        }
        if (StringUtils.isNotBlank(sysTenant.getTenantNickname())){
            lqw.like(SysTenant::getTenantNickname ,sysTenant.getTenantNickname());
        }
        if (StringUtils.isNotBlank(sysTenant.getEmail())){
            lqw.eq(SysTenant::getEmail ,sysTenant.getEmail());
        }
        if (StringUtils.isNotBlank(sysTenant.getPhonenumber())){
            lqw.eq(SysTenant::getPhonenumber ,sysTenant.getPhonenumber());
        }
        if (StringUtils.isNotBlank(sysTenant.getAddress())){
            lqw.eq(SysTenant::getAddress ,sysTenant.getAddress());
        }
        if (StringUtils.isNotBlank(sysTenant.getTitleName())){
            lqw.like(SysTenant::getTitleName ,sysTenant.getTitleName());
        }
        if (StringUtils.isNotBlank(sysTenant.getTitlePath())){
            lqw.eq(SysTenant::getTitlePath ,sysTenant.getTitlePath());
        }
        if (StringUtils.isNotBlank(sysTenant.getBgName())){
            lqw.like(SysTenant::getBgName ,sysTenant.getBgName());
        }
        if (StringUtils.isNotBlank(sysTenant.getBgPath())){
            lqw.eq(SysTenant::getBgPath ,sysTenant.getBgPath());
        }
        if (StringUtils.isNotBlank(sysTenant.getHomePath())){
            lqw.eq(SysTenant::getHomePath ,sysTenant.getHomePath());
        }
        if (StringUtils.isNotBlank(sysTenant.getStatus())){
            lqw.eq(SysTenant::getStatus ,sysTenant.getStatus());
        }
        if (StringUtils.isNotBlank(sysTenant.getTenantterm())){
            lqw.eq(SysTenant::getTenantterm ,sysTenant.getTenantterm());
        }
        if (StringUtils.isNotBlank(sysTenant.getTenantkey())){
            lqw.eq(SysTenant::getTenantkey ,sysTenant.getTenantkey());
        }
        if (StringUtils.isNotBlank(sysTenant.getTenantdomain())){
            lqw.eq(SysTenant::getTenantdomain ,sysTenant.getTenantdomain());
        }
        return this.list(lqw);
    }

    /**
     * 根据域名查询对应租户编码
     * @param domainString
     * @return
     */
    @Override
    public SysTenant queryDomainMapperTenant(String domainString) {
        return this.lambdaQuery()
                .like(com.linkwechat.common.utils.StringUtils.isNotBlank("tenantDomain"), SysTenant::getTenantdomain,domainString)
                .eq(StringUtils.isNotBlank("status"),SysTenant::getStatus,0)
                .one();
    }

    @Override
    public List<SysTenant> queryAllList() {
        return this.list();
    }

    @Override
    public List<SysTenantVo> getAllTenantInfo() {
        return this.baseMapper.getAllTenantInfo();
    }
}
